package com.study.cloud.apilog;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Date 2022/5/16
 * @Author Cliff
 * desc
 */
@Component
public class FilterExcludeUrl {

    @Value("${exclude.url: }")
    private String exclude;

    public boolean excludeUrls(String targetUrl) {
        if (StringUtils.isBlank(exclude)) {
            return false;
        }
        List<String> collect = Stream.of(exclude.split(",")).collect(Collectors.toList());
        PathMatcher antPathMatcher = new AntPathMatcher();
        return collect.stream()
                .anyMatch(url -> antPathMatcher.match(url, targetUrl));
    }


}
